<%--@elvariable id="REJECT" type="java.lang"--%>
<%--@elvariable id="PAST" type="java.lang"--%>
<%--
  Created by IntelliJ IDEA.
  User: gaoyang
  Date: 14-4-27
  Time: 下午9:43
  To change this template use File | Settings | File Templates.
--%>
<%--@elvariable id="myLoginId" type="java.lang.String"--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../../includes/common.jsp" %>
    <title>
        公示笔记列表
    </title>
</head>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline" action="">

        <label for="noteName">笔记名称</label>
        <input type="text" class="input-medium" name="noteName" id="noteName" value=""/>

        <label for="userName">公示人</label>
        <input type="text" name="userName" id="userName" value="" class="input-medium"/>

        <label for="noteState">笔记状态</label>
        <input type="text" name="noteState" id="noteState" value="" class="input-medium" flag="note_state"
               autocomplete="off"/>
        <input type="hidden" name="noteStateId" id="noteStateId" value="" autoHidden="autoHidden">

        <a class="btn btn-primary" onclick="query()">查询</a>
        <a class="btn btn-primary" onclick="pasting()">通过</a>
        <a class="btn btn-primary" onclick="rejecting()">驳回</a>
    </form>
    <table id="dataTable" style=""></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%"
                id="contentFrame"
                name="contentFrame"
                marginheight="0"
                marginwidth="0"
                frameborder="0" src=""
                allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    function query() {
        var noteType = $("#noteType").val();
        noteType = "" == noteType ? 0 : noteType;
        listOption.url = basePath + "note/publicity/listAllPublicityNote";
        listOption.data = "noteName=" + $("#noteName").val().trim() + "&userName=" + $("#userName").val() + "&noteState=" + $("#noteStateId").val();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='auditCheckBox']").attr("checked", true);
        } else {
            $("[name='auditCheckBox']").attr("checked", false);
        }
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "公示笔记列表",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'id', title: "&nbsp<input id='checkAll' type='checkbox' onclick='selectAll()'/>", align: 'center', width: 200},
                    {field: 'noteName', title: '笔记名称', sortable: true, align: 'center', width: 200},
                    {field: 'userName', title: '公示人', align: 'center', width: 200},
                    {field: 'noteType', title: '笔记类型', align: 'center', width: 200},
                    {field: 'publicityDate', title: '公示时间', sortable: true, align: 'center', width: 200},
                    {field: 'showState', title: '状态', align: 'center', width: 200},
                    {field: 'operate', title: '操作', align: 'center', width: 200}
                ]
            ],
            sortName: "",
            sortOrder: "",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "noteName":
                sortColumn = "note_name";
                break;
            case "publicityDate":
                sortColumn = "publicity_date";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='auditCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            editBtn = "&nbsp;<a onclick='user.edit(" + temp[i].id + "," + temp[i].note.id + ")'>查看</a>&nbsp;";
            temp[i].noteName = temp[i].note.noteName;
            temp[i].noteType = temp[i].note.noteType;
            temp[i].id = idBtn;
            temp[i].operate = editBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }

    function pasting() {
        var ids = getCheckedIds();
        audit(ids, "${PAST}", "通过");
    }

    function rejecting() {
        var ids = getCheckedIds();
        audit(ids, "${REJECT}", "驳回");
    }

    function getCheckedIds() {
        var ids = "";
        var value;
        var allBox = $("[name='auditCheckBox']");
        for (var i = 0, length = allBox.length; i < length; i++) {
            value = allBox[i].getAttribute("value");
            if ($("#" + value).attr("checked") == "checked") {
                if (value == 0) {

                }
                ids += value;
                if (i < length - 1) {
                    ids += ",";
                }
            }
        }
        return ids;
    }

    function audit(ids, state, operate) {
        $.messager.confirm("提示", "确认" + operate + "？", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "note/publicity/auditNote?ids=" + ids + "&state=" + state,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("成功", "已审核成功！", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
    }

    var user = {
        edit: function (id, noteId) {
            var contentFrame = $("#contentFrame");
            var dataEdit = $("#dataEdit");
            contentFrame[0].contentWindow.document.write("");
            contentFrame.attr("src", basePath + "note/publicity/auditNote?id=" + id + "&noteId=" + noteId);
            dataEdit.dialog({
                title: '编辑',
                height: 400,
                width: 600
            });
            dataEdit.dialog('open');
        }
    };

    $(function () {
        initDataGrid();
        query();
    })
</script>